package org.projetjava.presentation;

import java.awt.Desktop;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import javax.swing.JLabel;

public class ExecutionLienHyperText extends MouseAdapter{

	private String lien;
	
	public ExecutionLienHyperText(String lien)
	{
		this.lien = lien;	
	}
	  //Click sur le lien
    public void mouseClicked(MouseEvent e) {
        
        String plainText = this.lien.replaceAll("\\<.*?\\>", "");
        try {
            Desktop.getDesktop().browse(new URI(plainText));
        } catch (URISyntaxException ex) {
            //Logger.getLogger(JLabelHyperlink.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            //Logger.getLogger(JLabelHyperlink.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    //Survol sur le lien
    public void mouseEntered(MouseEvent e) {
        JLabel label=(JLabel)e.getSource();
        String plainText = label.getText().replaceAll("\\<.*?\\>", "");
        //Sousligner le texte 
        String urlText="<html><u>"+plainText+"</u></html>";
        label.setText(urlText);
    }

    //Quitte la zone du lien    
    public void mouseExited(MouseEvent e) {
        JLabel label=(JLabel)e.getSource();
        String plainText = label.getText().replaceAll("\\<.*?\\>", "");
        //Texte sans souslignage
        String urlText="<html>"+plainText+"</html>";
        label.setText(urlText);
    }
}
